let  {bytecode, interface} = require("./compile")
let Web3 = require("web3")
// console.log('bytecode:',bytecode)
// console.log('interface:',interface)
const account = "0xD5fFa32A808970FAb637AeE4ca70e00888B3e4D8"
let web3 = new Web3();
//console.log("版本:",web3.version)
//1.设置网络
web3.setProvider('HTTP://127.0.0.1:7545');
//console.log(web3.providers)
//产看当前的currentProvider
//console.log(web3.currentProvider)
//2.拼接合约数据
let contract = new web3.eth.Contract(JSON.parse(interface))
//console.log("自己的contract:",contract)
web3.eth.defaultAccount = account;
//设置默认的账户
console.log("默认的账户",web3.eth.defaultAccount)
//console.log(contract.defaultBlock)
// //3.拼接bytecode

contract.deploy({
    data:bytecode,
    arguments: ["success"]
})
    .send({
        from: account,
        gas: 5721975,
        gasPrice: '300000000000'
    })
    .then(function(newContractInstance){
        //newContractInstance.options.address 得到的是新的合约的地址
        address = newContractInstance.options.address
        console.log("得到部署合约的地址",address) // instance with the new contract address
    });